package com.fenghen.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.fenghen.common.annotation.Log;
import com.fenghen.common.enums.BusinessType;
import com.fenghen.system.domain.RiskAssessment;
import com.fenghen.system.service.IRiskAssessmentService;
import com.fenghen.common.core.controller.BaseController;
import com.fenghen.common.core.domain.AjaxResult;
import com.fenghen.common.utils.poi.ExcelUtil;
import com.fenghen.common.core.page.TableDataInfo;

/**
 * 风险评估与评级模块Controller
 * 
 * @author fenghen
 * @date 2024-11-06
 */
@Controller
@RequestMapping("/system/assessment")
public class RiskAssessmentController extends BaseController
{
    private String prefix = "system/assessment";

    @Autowired
    private IRiskAssessmentService riskAssessmentService;

    @RequiresPermissions("system:assessment:view")
    @GetMapping()
    public String assessment()
    {
        return prefix + "/assessment";
    }

    /**
     * 查询风险评估与评级模块列表
     */
    @RequiresPermissions("system:assessment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RiskAssessment riskAssessment)
    {
        startPage();
        List<RiskAssessment> list = riskAssessmentService.selectRiskAssessmentList(riskAssessment);
        return getDataTable(list);
    }

    /**
     * 导出风险评估与评级模块列表
     */
    @RequiresPermissions("system:assessment:export")
    @Log(title = "风险评估与评级模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RiskAssessment riskAssessment)
    {
        List<RiskAssessment> list = riskAssessmentService.selectRiskAssessmentList(riskAssessment);
        ExcelUtil<RiskAssessment> util = new ExcelUtil<RiskAssessment>(RiskAssessment.class);
        return util.exportExcel(list, "风险评估与评级模块数据");
    }

    /**
     * 新增风险评估与评级模块
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存风险评估与评级模块
     */
    @RequiresPermissions("system:assessment:add")
    @Log(title = "风险评估与评级模块", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RiskAssessment riskAssessment)
    {
        return toAjax(riskAssessmentService.insertRiskAssessment(riskAssessment));
    }

    /**
     * 修改风险评估与评级模块
     */
    @RequiresPermissions("system:assessment:edit")
    @GetMapping("/edit/{assessmentId}")
    public String edit(@PathVariable("assessmentId") Long assessmentId, ModelMap mmap)
    {
        RiskAssessment riskAssessment = riskAssessmentService.selectRiskAssessmentByAssessmentId(assessmentId);
        mmap.put("riskAssessment", riskAssessment);
        return prefix + "/edit";
    }

    /**
     * 修改保存风险评估与评级模块
     */
    @RequiresPermissions("system:assessment:edit")
    @Log(title = "风险评估与评级模块", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RiskAssessment riskAssessment)
    {
        return toAjax(riskAssessmentService.updateRiskAssessment(riskAssessment));
    }

    /**
     * 删除风险评估与评级模块
     */
    @RequiresPermissions("system:assessment:remove")
    @Log(title = "风险评估与评级模块", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(riskAssessmentService.deleteRiskAssessmentByAssessmentIds(ids));
    }
}
